{include file="public/header"}
<body>
<fieldset class="layui-elem-field">
    <legend>下级代理商向我提交的订单</legend>
    <div class="layui-field-box">
        <form id="searchForm" method="" action="">
            <span id="reload" class="layui-btn layui-btn-normal">全部订单</span>
            <span id="not_delivery" class="layui-btn layui-btn-normal">未发放订单</span>
            <div class="layui-inline">
                <label class="layui-form-label">按代理商名</label>
                <div class="layui-input-inline">
                    <input type="text" name="agent_name" placeholder="输入代理商名称" required lay-verify="required" value="" autocomplete="off" class="layui-input">
                </div>
            </div>
            <span id="seach" class="layui-btn layui-btn-normal"><i class="layui-icon">&#xe615;</i> 收索</span>
        </form>

        <table class="layui-table" lay-even>
            <thead>
            <tr>
                <th>Id</th>
                <th>下级代理商姓名</th>
                <th>电话</th>
                <th>订单交易个数</th>
                <th>创建日期</th>
                <th>交易状态</th>
                <th>操作</th>
            </tr>
            </thead>
            <tbody  id="searchContent">
            {volist name="list" id="vo"}
            <tr>
                <td>{$vo['id']}</td>
                <td>{$vo['name']}</td>
                <td>{$vo['mobile']}</td>
                <td>{$vo['num']}</td>
                <td>{$vo['create_time']}</td>
                {if condition="$vo['is_delivery'] == 0"}
                <td><span style="border-radius: 2px;background-color: #FF5722;padding:5px 10px;color: #ffffff">未发放</span></td>
                <td>
                    <span onclick="detail({$vo['id']})" class="layui-btn layui-btn-normal">查看详情</span>
                    <span onclick="allotCode({$vo['aid']},{$vo['id']},{$vo['num']})" class="layui-btn">下发激活码</span>
                </td>
                {else /}
                <td><span style="border-radius: 2px;background-color: #5FB878;padding:5px 10px;color: #ffffff">已发放</span></td>
                <td>
                    <span onclick="detail({$vo['id']})" class="layui-btn layui-btn-normal">查看详情</span>
                </td>
                {/if}
            </tr>
            {/volist}
            </tbody>
        </table>

        <div>{$list->render()}</div>
    </div>
</fieldset>


{include file="public/footer"}
<script>
    layui.use(['layer'], function() {});


    function detail(id) {
        layer.open({
            type: 2,
            area: ['90%', '90%'],
            title: '订单详情',
            maxmin: true,
            content: '/agent/order/detail/id/'+id
        });
    }
    function allotCode(id,order,num) {
        layer.open({
            type: 2,
            area: ['90%', '90%'],
            title: '订单详情',
            maxmin: true,
            content: '/admin/key/allotCode/id/'+id+'/order/'+order+'/num/'+num
        });
    }

    $('#seach').on('click', function () {
        let name = $("input[name='agent_name']").attr('value').trim();
        if(name == null || name == undefined || name == '') {
            dialog.toconfirm('收索条件不能为空或空格');
            return false;
        }
        var params  = {
            url : "{:url('')}",
            data: $("#searchForm").serialize(),
            type: 'post',
            sCallback:function(res){
                var travelHtml = [];
                for (var i=0; i < res.data.length; i++) {
                    var id = res.data[i]["id"];
                    if(res.data[i]["is_delivery"] == 0) {
                        var condition = '<td><span style="border-radius: 2px;background-color: #FF5722;padding:5px 10px;color: #ffffff">未发放</span></td>' +
                                '<td>' +
                                '<span onclick="detail('+id+')" class="layui-btn layui-btn-normal">查看详情</span>' +
                                '<span onclick="allotCode('+res.data[i]["aid"]+','+res.data[i]["id"]+','+res.data[i]["num"]+')" class="layui-btn">下发激活码</span>'+
                                '</td>';
                    }else {
                        var condition = '<td><span style="border-radius: 2px;background-color: #5FB878;padding:5px 10px;color: #ffffff">已发放</span></td>' +
                                '<td><span onclick="detail('+id+')" class="layui-btn layui-btn-normal">查看详情</span></td>';
                    }

                    travelHtml +='<tr> ' + '<td>'+(i+1)+'</td> ' +
                            '<td>'+res.data[i]["name"]+'</td> ' +
                            '<td>'+res.data[i]["mobile"]+'</td> ' +
                            '<td>'+res.data[i]["num"]+'</td> ' +
                            '<td>'+res.data[i]["create_time"]+'</td> ' + condition +
                            '</tr>';
                };
                $('#searchContent').html(travelHtml);
            }
        };
        common.request(params);
    });
    $('#reload').click(function () {
        window.location.href = "{:url('width_agent')}";
    });
    $('#not_delivery').click(function () {
        window.location.href = "{:url('width_agent', array('delivery' => 'no'))}";
    });
</script>
</body>
</html>